package com.example.dell.wisdom_farm;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ZhuCeActivity extends AppCompatActivity implements View.OnClickListener{

    private Button button;
    private EditText editText_name,editText_password,editText_password_confirm,editText_mailbox,editText_phone_number;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu_ce);
        button=(Button)findViewById(R.id.register_btn);
        editText_name=(EditText)findViewById(R.id.register_name);
        editText_password=(EditText)findViewById(R.id.register_password);
        editText_password_confirm=(EditText)findViewById(R.id.register_password_confirm);
        editText_mailbox=(EditText)findViewById(R.id.register_mailbox);
        editText_phone_number=(EditText)findViewById(R.id.register_phone_number);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v){
        String text1=editText_name.getText().toString();
        String text2=editText_password.getText().toString();
        String text3=editText_password_confirm.getText().toString();
        String text4=editText_mailbox.getText().toString();
        String text5=editText_phone_number.getText().toString();

      //  int x=Integer.parseInt(text2);
      //  int y=Integer.parseInt(text3)

        switch (v.getId()){
            case R.id.register_btn:
                if(text1.isEmpty()){
                    Toast.makeText(this, "姓名不能为空", Toast.LENGTH_LONG).show();
                }
                else if(text2.isEmpty()){
                    Toast.makeText(this, "密码不能为空", Toast.LENGTH_LONG).show();
                }else if(text3.isEmpty()){
                    Toast.makeText(this, "确认密码不能为空", Toast.LENGTH_LONG).show();
                }else if(text4.isEmpty()){
                    Toast.makeText(this, "邮箱不能为空", Toast.LENGTH_LONG).show();
                }else if(text5.isEmpty()){
                    Toast.makeText(this, "电话号码不能为空", Toast.LENGTH_LONG).show();
                }
                else if(!text2.equals(text3)){
                    Toast.makeText(this, "两次密码需要相同", Toast.LENGTH_LONG).show();
                }
                else{
                    Toast.makeText( this,"注册成功",Toast.LENGTH_LONG).show();
                    Intent intent=new Intent(ZhuCeActivity.this,LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
        }
    }
}
